package com.taritari.journal.controller;

import com.taritari.journal.entity.dto.CommentDto;
import com.taritari.journal.entity.dto.UserLikeDto;
import com.taritari.journal.entity.vo.CommentVo;
import com.taritari.journal.services.CommentService;
import com.taritari.journal.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author taritari
 * @date 2024-01-24 15:12
 * @description 评论表
 */
@RestController
@Slf4j
@Tag(name = "评论接口", description = "评论接口")
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @GetMapping("/getComment")
    @Operation(summary = "通过树洞Id获取评论", description = "通过树洞Id获取评论")
    public Result getComment(@RequestParam int treeHoldId,@RequestParam int orderBy){
        List<CommentVo> comment = commentService.getComment(treeHoldId, orderBy);
        return Result.success(comment);
    }
    @GetMapping("/isLike")
    @Operation(summary = "查询用户是否喜欢评论", description = "查询用户是否喜欢评论")
    public Result isLike(@RequestParam int userId,@RequestParam int commentId){
        int res = commentService.userIsLikeComment(userId, commentId);
        return Result.success(res);
    }
    @PostMapping("/like")
    @Operation(summary = "用户点击喜欢", description = "用户点击喜欢")
    public Result clickLike(@RequestBody UserLikeDto userLikeDto){
        commentService.commentLikeMq(userLikeDto);
        return Result.success();
    }
    @PostMapping("/add")
    @Operation(summary = "添加评论", description = "添加评论")
    public Result addComment(@RequestBody CommentDto commentDto){
        int res = commentService.insertComment(commentDto);
        return Result.success(res);
    }
    @GetMapping("/count")
    @Operation(summary = "通过树洞id获取评论数", description = "通过树洞id获取评论数")
    public Result getCount(@RequestParam int treeHoldId){
        int count = commentService.getCount(treeHoldId);
        return Result.success(count);
    }


}
